package com.neusoft.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.crm.entity.Chance;
import com.neusoft.crm.mapper.ChanceMapper;
import com.neusoft.crm.service.IChanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.crm.tools.CommonResult;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lplpok
 * @since 2023-06-20
 */
@Service
public class ChanceServiceImpl extends ServiceImpl<ChanceMapper, Chance> implements IChanceService {

    @Override
    public CommonResult qryList4FeedBack(String begin, String end, String customerno, String productno, String service) {
        QueryWrapper<Chance> wrapper = new QueryWrapper<>();
        LocalDate beginDate = LocalDate.parse(begin);
        LocalDate endDate = LocalDate.parse(end);

        wrapper.eq("ft",beginDate);
        wrapper.eq("bt",endDate);
        wrapper.eq("customerno",Integer.valueOf(customerno));
        wrapper.eq("productno",Integer.valueOf(productno));
        List<Chance> list = list(wrapper);
        if(list == null || list.size() == 0){
            return new CommonResult(null,204);
        }
        return new CommonResult(list);
    }

    @Override
    public CommonResult qryList(Integer customerno, Integer productno, String service) {
        QueryWrapper<Chance> wrapper = new QueryWrapper<>();
        if(customerno != null && productno != null) {
            wrapper.eq("customerno", customerno);
            wrapper.eq("productno", productno);
        }
        List<Chance> list = list(wrapper);
        if(list == null || list.size() == 0){
            return new CommonResult(null,204);
        }
        return new CommonResult(list);
    }
}
